﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract OsnovaOsiguranjaTip typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class OsnovaOsiguranjaTipDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<OsnovaOsiguranjaTipDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.OsnovaOsiguranjaTip _currentOsnovaOsiguranjaTip = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxOsnovaOsiguranjaTipDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxOsnovaOsiguranjaTipErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxOsnovaOsiguranjaTipBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Naziv property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNazivDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.OsnovaOsiguranjaTip> _OsnovaOsiguranjaTipList;
				
		/// <summary> 
		/// The list of OsnovaOsiguranjaTip to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.OsnovaOsiguranjaTip> OsnovaOsiguranjaTipList
		{
			get {return this._OsnovaOsiguranjaTipList;}
			set
			{
				this._OsnovaOsiguranjaTipList = value;
				this.uxOsnovaOsiguranjaTipBindingSource.DataSource = null;
				this.uxOsnovaOsiguranjaTipBindingSource.DataSource = value;
				this.uxOsnovaOsiguranjaTipDataGridView.DataSource = null;
				this.uxOsnovaOsiguranjaTipDataGridView.DataSource = this.uxOsnovaOsiguranjaTipBindingSource;				
				//this.uxOsnovaOsiguranjaTipBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxOsnovaOsiguranjaTipBindingSource_ListChanged);
				this.uxOsnovaOsiguranjaTipBindingSource.CurrentItemChanged += new System.EventHandler(OnOsnovaOsiguranjaTipBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnOsnovaOsiguranjaTipBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentOsnovaOsiguranjaTip = uxOsnovaOsiguranjaTipBindingSource.Current as Entities.OsnovaOsiguranjaTip;
			
			if (_currentOsnovaOsiguranjaTip != null)
			{
				_currentOsnovaOsiguranjaTip.Validate();
			}
			//_OsnovaOsiguranjaTip.Validate();
			OnCurrentEntityChanged();
		}

		//void uxOsnovaOsiguranjaTipBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.OsnovaOsiguranjaTip"/> instance.
		/// </summary>
		public Entities.OsnovaOsiguranjaTip SelectedOsnovaOsiguranjaTip
		{
			get {return this._currentOsnovaOsiguranjaTip;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxOsnovaOsiguranjaTipDataGridView.VirtualMode;}
			set
			{
				this.uxOsnovaOsiguranjaTipDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxOsnovaOsiguranjaTipDataGridView.AllowUserToAddRows;}
			set {this.uxOsnovaOsiguranjaTipDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxOsnovaOsiguranjaTipDataGridView.AllowUserToDeleteRows;}
			set {this.uxOsnovaOsiguranjaTipDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxOsnovaOsiguranjaTipDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxOsnovaOsiguranjaTipDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="OsnovaOsiguranjaTipDataGridViewBase"/> class.
		/// </summary>
		public OsnovaOsiguranjaTipDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxOsnovaOsiguranjaTipDataGridView = new System.Windows.Forms.DataGridView();
			this.uxOsnovaOsiguranjaTipBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxOsnovaOsiguranjaTipErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNazivDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxOsnovaOsiguranjaTipErrorProvider
			// 
			this.uxOsnovaOsiguranjaTipErrorProvider.ContainerControl = this;
			this.uxOsnovaOsiguranjaTipErrorProvider.DataSource = this.uxOsnovaOsiguranjaTipBindingSource;						
			// 
			// uxOsnovaOsiguranjaTipDataGridView
			// 
			this.uxOsnovaOsiguranjaTipDataGridView.AutoGenerateColumns = false;
			this.uxOsnovaOsiguranjaTipDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxOsnovaOsiguranjaTipDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxNazivDataGridViewColumn			});
			this.uxOsnovaOsiguranjaTipDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxOsnovaOsiguranjaTipDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxOsnovaOsiguranjaTipDataGridView.Name = "uxOsnovaOsiguranjaTipDataGridView";
			this.uxOsnovaOsiguranjaTipDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxOsnovaOsiguranjaTipDataGridView.TabIndex = 0;	
			this.uxOsnovaOsiguranjaTipDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxOsnovaOsiguranjaTipDataGridView.EnableHeadersVisualStyles = false;
			this.uxOsnovaOsiguranjaTipDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnOsnovaOsiguranjaTipDataGridViewDataError);
			this.uxOsnovaOsiguranjaTipDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnOsnovaOsiguranjaTipDataGridViewCellValueNeeded);
			this.uxOsnovaOsiguranjaTipDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnOsnovaOsiguranjaTipDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxNazivDataGridViewColumn
			//
			this.uxNazivDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNazivDataGridViewColumn.DataPropertyName = "Naziv";
			this.uxNazivDataGridViewColumn.HeaderText = "Naziv";
			this.uxNazivDataGridViewColumn.Name = "uxNazivDataGridViewColumn";
			this.uxNazivDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNazivDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNazivDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxOsnovaOsiguranjaTipDataGridView);
			this.Name = "OsnovaOsiguranjaTipDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxOsnovaOsiguranjaTipBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				OsnovaOsiguranjaTipDataGridViewEventArgs args = new OsnovaOsiguranjaTipDataGridViewEventArgs();
				args.OsnovaOsiguranjaTip = _currentOsnovaOsiguranjaTip;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class OsnovaOsiguranjaTipDataGridViewEventArgs : System.EventArgs
		{
			private Entities.OsnovaOsiguranjaTip	_OsnovaOsiguranjaTip;
	
			/// <summary>
			/// the  Entities.OsnovaOsiguranjaTip instance.
			/// </summary>
			public Entities.OsnovaOsiguranjaTip OsnovaOsiguranjaTip
			{
				get { return _OsnovaOsiguranjaTip; }
				set { _OsnovaOsiguranjaTip = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxOsnovaOsiguranjaTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnOsnovaOsiguranjaTipDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxOsnovaOsiguranjaTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnOsnovaOsiguranjaTipDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxOsnovaOsiguranjaTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = OsnovaOsiguranjaTipList[e.RowIndex].ID;
						break;
					case "uxNazivDataGridViewColumn":
						e.Value = OsnovaOsiguranjaTipList[e.RowIndex].Naziv;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxOsnovaOsiguranjaTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnOsnovaOsiguranjaTipDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxOsnovaOsiguranjaTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						OsnovaOsiguranjaTipList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxNazivDataGridViewColumn":
						OsnovaOsiguranjaTipList[e.RowIndex].Naziv = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
